package com.aierjun.ani.net.OkGo;

import com.lzy.okgo.convert.StringConvert;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Progress;
import com.lzy.okgo.request.PostRequest;
import com.lzy.okserver.OkUpload;
import com.lzy.okserver.upload.UploadListener;
import com.lzy.okserver.upload.UploadTask;

/**
 * Created by Ani_aierJun on 2017/10/12.
 */

public class UploadUtils {
    private static UploadTask<String> task;


    public static UploadTask<String> upload(String url, HttpHeaders headers, HttpParams httpParams, String tag , int priority,UploadListener<String> uploadListener){
        PostRequest<String> postRequest = com.lzy.okgo.OkGo.<String>post(url);
        if (headers != null)
            postRequest.headers(headers);
        if (httpParams != null)
            postRequest.params(httpParams);
        postRequest.converter(new StringConvert());
        task = OkUpload.request(tag,postRequest)
                .priority(priority)//优先级
//                .extra1() //额外的数据
                .save()
                .register(uploadListener);
        return task;

    }

    public static void startUpload(){
        task.start();
    }

    public static void pauseUpload(){
        task.pause();
    }

    public static void removeUpload(){
        task.remove();
    }

    public static void restartUpload(){
        task.restart();
    }
}
